//
//  ChannelBookCell.m
//  ZYTS-iPhone
//
//  Created by yuzhou on 12-12-13.
//  Copyright (c) 2012年 wzyk. All rights reserved.
//

#import "ChannelBookCell.h"
#import "UIImageView+WebCache.h"
#import <QuartzCore/QuartzCore.h>

@implementation ChannelBookCell

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
{
//    NSLog(@"%s",__FUNCTION__);
    self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
        self.contentView.backgroundColor = [UIColor clearColor];
        
        coverImageView = [[[UIImageView alloc] initWithFrame:CGRectMake(2, 6, 93, 115)] autorelease];
        coverImageView.contentMode = UIViewContentModeScaleToFill;
        coverImageView.image = [UIImage imageNamed:@"default_image"];
        [self.contentView addSubview:coverImageView];
        
        coverImageView.layer.shadowColor = [UIColor blackColor].CGColor;
        coverImageView.layer.shadowOpacity = 0.45f;
        coverImageView.layer.shadowOffset = CGSizeMake(-4.0f, 0.0f);
        coverImageView.layer.masksToBounds = NO;
        UIBezierPath *path = [UIBezierPath bezierPathWithRect:coverImageView.frame];
        coverImageView.layer.shadowPath = path.CGPath;
        
        titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(2, 91, 93, 15)] autorelease];
        titleLabel.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
        titleLabel.textAlignment = UITextAlignmentCenter;
        titleLabel.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.6];
        titleLabel.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:titleLabel];
        
        chapterCountLabel = [[[UILabel alloc] initWithFrame:CGRectMake(2, 106, 93, 15)] autorelease];
        chapterCountLabel.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
        chapterCountLabel.textAlignment = UITextAlignmentCenter;
        chapterCountLabel.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.6];
        chapterCountLabel.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:chapterCountLabel];
    }
    return self;
}

- (void)updateDisplay
{
    if (self.bookInfo) {
        NSString *imageURL = [[_bookInfo valueForKey:@"image"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [coverImageView setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:[UIImage imageNamed:@"default_image"] options:SDWebImageRetryFailed];
        titleLabel.text = [_bookInfo objectForKey:@"item_name"];
        chapterCountLabel.text = [NSString stringWithFormat:@"共%@集",[_bookInfo objectForKey:@"sub_count"]];
    }
}

- (void)dealloc
{
    NSLog(@"%s",__FUNCTION__);
    [_bookInfo release];
    [super dealloc];
}

@end
